package com.ctshk.common.utils;

import com.alibaba.fastjson.JSON;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class CharUtil {

    public static String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static String charsAll = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    public static String[] weekDays = new String[]{"一", "二", "三", "四", "五", "六", "日"};

    public static String getChar(int position) {
        return chars.charAt(position) + "";
    }

    public static String getWeekDay(int val) {
        return weekDays[val - 1];
    }

    private static List<String> domesticCode = Arrays.asList("+86", "86");

    /**
     * 生成随机字符串
     */
    public static String getRandomStr(int l) {
        String str = "";
        for (int i = 0; i < l; i++) {
            str += (int) (Math.random() * 10);
        }
        return str;
    }

    /**
     * 生成随机字符串（字母+数字）
     * @Param i 字符长度
     * @Param j 数字长度
     */
    public static String getNumber(int i,int j) {
        StringBuffer sb = new StringBuffer();
        Random random=new Random();
        for (int a = 0; a < i; a++) {
            int number=random.nextInt(52);
            sb.append(charsAll.charAt(number));
        }
        for (int b = 0; b < j; b++) {
            sb.append((int) (Math.random() * 10));
        }
        return sb.toString();
    }

    /**
     * 生成随机字符串(字母，数字)
     *
     * @param length 随机字符串长度
     * @return
     */
    public static String genRandomNum(int length) {
        int maxNum = 36;
        int i;
        int count = 0;
        char[] str = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
                'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
                'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        StringBuffer pwd = new StringBuffer("");
        Random r = new Random();
        while (count < length) {
            i = Math.abs(r.nextInt(maxNum));
            if (i >= 0 && i < str.length) {
                pwd.append(str[i]);
                count++;
            }
        }
        return pwd.toString();
    }

    /**
     * 判断是否是国内号码
     *
     * @param contactMobileAreaCode
     */
    public static boolean isDomestic(String contactMobileAreaCode) {
        boolean flag = false;
        for (String code : domesticCode) {
            flag = contactMobileAreaCode.contains(code);
            if(flag){
                return flag;
            }
        }
        return flag;
    }

    /**
     * 数组转sql字符串
     * @param idList
     * @return
     */
    public static String listToSqlStr(List idList) {
        String str = JSON.toJSONString(idList);
        str = str.replaceAll("\\[","(");
        str = str.replaceAll("\\]",")");
        return str;
    }


}
